const std = @import("std");
const Allocator = std.mem.Allocator;
const DoublyLinkedList = std.DoublyLinkedList;

pub const dprint = std.debug.print;

test "test arraylist" {}

test "test doublylinkedlist" {
    // var allocator = std.testing.allocator;
    const L = DoublyLinkedList(i32);
    var list = L{};
    var one = L.Node{ .data = 1 };

    list.append(&one);
    try std.testing.expect(list.first.?.data == 1);
}

const MyNode = struct {
    allocator: *Allocator,
    list: DoublyLinkedList(i32),

    pub fn init(allocator: *Allocator) MyNode {
        return MyNode{
            .allocator = allocator,
            .list = DoublyLinkedList(i32){},
        };
    }

    pub fn append(self: *MyNode, value: i32) !void {
        const node = try self.allocator.create(DoublyLinkedList(i32).Node);
        node.* = DoublyLinkedList(i32).Node{ .data = value };
        self.list.append(node);
    }

    pub fn deinit(self: *MyNode) void {
        var it = self.list.first;
        while (it) |node| {
            const next = node.next;
            self.list.remove(node);
            self.allocator.destroy(node);
            it = next;
        }
    }
};
